package com.shqcjd.generalplatformprojectclient.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.generalplatformprojectclient.R;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceHistoryBean;
import com.shqcjd.generalplatformprojectclient.util.DateUtil;

import java.util.List;

/**
 * 指导文件
 * Created by sy on 2018/12/17.
 */

public class GuidanceFileAdapter extends BaseQuickAdapter<GuidanceHistoryBean.GuideVideoBean,BaseViewHolder> {
    private Context context;
    public GuidanceFileAdapter( @Nullable List<GuidanceHistoryBean.GuideVideoBean> data,Context context) {
        super(R.layout.item_guidance_file, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, GuidanceHistoryBean.GuideVideoBean item) {
        helper.setText(R.id.tv_guide_file_type, item.filename.substring(item.filename.lastIndexOf(".") + 1).substring(0,1))
                .setText(R.id.tv_guide_file_size,item.size)
                .setText(R.id.tv_guide_file_name,item.filename)
                .setText(R.id.tv_guide_file_date, DateUtil.getDateToString(item.uploadTime,"yyyy-MM-dd HH:mm:ss"));
        if(item.extension.equals(".mp4")){
            helper.getView(R.id.fl_type).setVisibility(View.INVISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.VISIBLE);
            Glide.with( context )
                    .load(item.url)
                    .thumbnail( 0.1f )
                    .into((ImageView) helper.getView(R.id.iv_type));
        }else if(item.extension.equals(".jpg")||item.extension.equals(".png")){
            helper.getView(R.id.fl_type).setVisibility(View.INVISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.VISIBLE);
            Glide.with( context )
                    .load(item.url)
                    .into((ImageView) helper.getView(R.id.iv_type));
        }else {
            helper.getView(R.id.fl_type).setVisibility(View.VISIBLE);
            helper.getView(R.id.iv_type).setVisibility(View.INVISIBLE);


        }
    }
}
